home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / handson.exe / FRUNIT4.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-01-31  |  5.5 KB  |  191 lines

  1. unit Frunit4;
  2. { PC Plus sample Delphi program. A simple French verb conjugator - mark 4 }
  3. { This now deals with regular ER, IR and RE verbs. It illustrates the use }
  4. { of standard Pascal procedures                                           }
  5. {                                                                         }
  6. { Note the use of WITH                                                    }
  7. {      in     With Form1.ListBox1.Items do                                }
  8. {                                                                         }
  9. { Also the 'shortcut' way of calling the JePlusStem function              }
  10. { i.e Instead of declaring an intermediate string variable, 's'           }
  11. { and then using the expressions:                                         }
  12. {             s := JePlusStem(vStem);                                     }
  13. {             Add( s + 'e');                                              }
  14. { this has all been done in one go:                                       }
  15. {             Add(JePlusStem(vStem) + 'e');                               }
  16.  
  17.  
  18.  
  19. interface
  20.  
  21. uses
  22.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  23.   Forms, Dialogs, StdCtrls;
  24.  
  25. type
  26.   TForm1 = class(TForm)
  27.     ListBox1: TListBox;
  28.     Edit1: TEdit;
  29.     Label1: TLabel;
  30.     Button1: TButton;
  31.     procedure Button1Click(Sender: TObject);
  32.   private
  33.     { Private declarations }
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. var
  39.   Form1: TForm1;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44. procedure ConjugateALLER;
  45. begin
  46.   With Form1.ListBox1.Items do
  47.   begin
  48.    Clear;
  49.    Add('Je vais');
  50.    Add('Tu vas');
  51.    Add('Il va');
  52.    Add('Elle va');
  53.    Add('Nous allons');
  54.    Add('Vous allez');
  55.    Add('Ils vont');
  56.    Add('Elles vont');
  57.   end;
  58. end;
  59.  
  60. procedure ConjugateAVOIR;
  61. begin
  62.   With Form1.ListBox1.Items do
  63.   begin
  64.    Clear;
  65.    Add('J''ai');
  66.    Add('Tu as');
  67.    Add('Il a');
  68.    Add('Elle a');
  69.    Add('Nous avons');
  70.    Add('Vous avez');
  71.    Add('Ils ont');
  72.    Add('Elles ont');
  73.   end;
  74. end;
  75.  
  76. procedure ConjugateETRE;
  77. begin
  78.   With Form1.ListBox1.Items do
  79.   begin
  80.    Clear;
  81.    Add('Je suis');
  82.    Add('Tu es');
  83.    Add('Il est');
  84.    Add('Elle est');
  85.    Add('Nous sommes');
  86.    Add('Vous etes');
  87.    Add('Ils sont');
  88.    Add('Elles sont');
  89.   end;
  90. end;
  91.  
  92. function JePlusStem( vStem : string ) : string;
  93. { Function checks to see if a vowel begins the verb. If so           }
  94. { it retuns "J'" plus verb stem. Else, it reurns "Je " plus verbStem }
  95. Const { declare vowels as a set of characters                        }
  96.   vowels : set of char = ['a','e','i','o','u','y'];
  97. begin { see if 1st letter of vStem is in the set named 'vowels'      }
  98.    if vStem[1] in vowels then
  99.       JePlusStem := 'J''' + vStem
  100.    else
  101.       JePlusStem := 'Je ' + vStem;
  102. end;
  103.  
  104.  
  105. procedure ConjugateERverb( vStem : string );
  106. begin
  107.    with Form1.ListBox1.Items do
  108.    begin
  109.      Clear;
  110.       { call the JePlusStem function to return the Je form }
  111.      Add(JePlusStem(vStem) + 'e');
  112.      Add('Tu ' + vStem + 'es' );
  113.      Add('Il ' + vStem + 'e' );
  114.      Add('Elle ' + vStem + 'e' );
  115.      Add('Nous ' + vStem + 'ons' );
  116.      Add('Vous ' + vStem + 'ez' );
  117.      Add('Ils ' + vStem + 'ent');
  118.      Add('Elles ' + vStem + 'ent');
  119.    end;
  120. end;
  121.  
  122. procedure ConjugateREverb( vStem : string );
  123. begin
  124.    with Form1.ListBox1.Items do
  125.    begin
  126.      Clear;
  127.      Add(JePlusStem(vStem) + 's');
  128.      Add('Tu ' + vStem + 's' );
  129.      Add('Il ' + vStem  );
  130.      Add('Elle ' + vStem  );
  131.      Add('Nous ' + vStem + 'ons' );
  132.      Add('Vous ' + vStem + 'ez' );
  133.      Add('Ils ' + vStem + 'ent');
  134.      Add('Elles ' + vStem + 'ent');
  135.    end;
  136. end;
  137.  
  138. procedure ConjugateIRverb( vStem : string );
  139. begin
  140.    with Form1.ListBox1.Items do
  141.    begin
  142.      Clear;
  143.      Add(JePlusStem(vStem) + 'is');
  144.      Add('Tu ' + vStem + 'is' );
  145.      Add('Il ' + vStem + 'it' );
  146.      Add('Elle ' + vStem + 'it' );
  147.      Add('Nous ' + vStem + 'issons' );
  148.      Add('Vous ' + vStem + 'issez' );
  149.      Add('Ils ' + vStem + 'issent');
  150.      Add('Elles ' + vStem + 'issent');
  151.    end;
  152. end;
  153.  
  154. procedure TForm1.Button1Click(Sender: TObject);
  155. var                  { --- Declare 3 string variables --- }
  156.   verb,              { the verb specified by the user     }
  157.   verbStem,          { the verb minus its 2-letter ending }
  158.   verbEnd : string;  { the 2-letter ending                }
  159. begin
  160.   verb := LowerCase( Edit1.Text );{ make text lower case  }
  161.        { check that the user has entered something...     }
  162.   if verb = '' then
  163.      Caption := 'You must enter a verb!'
  164.   else
  165.   begin {... if so, then                              }
  166.         { find the stem and the ending of the verb    }
  167.     verbStem := copy( verb, 1, length(verb)-2 );
  168.     verbEnd  := copy( verb, length(verb) -1, 2 );
  169.     Caption  := 'This is an ' + verbEnd + ' verb.';
  170.         { find type of verb and call appropriate proc }
  171.         { ---- check for IRREGULAR verbs ------------ }
  172.     if verb = 'aller' then
  173.        conjugateALLER
  174.     else if verb = 'etre' then
  175.        conjugateETRE
  176.     else if verb = 'avoir' then
  177.        conjugateAVOIR
  178.        { ------ then deal with REGULAR verbs -------- }
  179.     else if verbEnd = 'er' then
  180.        ConjugateERverb( verbStem )
  181.     else if verbEnd = 're' then
  182.        ConjugateREverb( verbStem )
  183.     else if verbEnd = 'ir' then
  184.        ConjugateIRverb( verbStem )
  185.     else         { if this isn't an ER, RE or IR verb, show error msg... }
  186.        Caption := 'You must enter an ER, RE or IR verb!';
  187.   end;
  188. end;
  189.  
  190. end.
  191.